/**
 * 
 */
package type;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import common.MyBean;

/**
 * url:http://127.0.0.1:8080/JSPSessionAttributeListener/type<br>
 * PS:請將 timeout 設定為一分鐘, 方便測試<br>
 * <br>
 * 當 SessionAttributeListener.attributeRemoved() 這個方法被呼叫時, 會有二種情形:<br>
 * 1. 使用者登出(程式呼叫 session.removeAttribute()<br>
 * 2. timeout<br> 
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class TypeServlet extends HttpServlet
{
	private static final long serialVersionUID = -8144101358509724368L;

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		MyBean bean = new MyBean();
		bean.setName( "eric.kao" );
		
		HttpSession session = request.getSession( true );
		
		session.setAttribute( "MyBean", bean );
		session.removeAttribute( "MyBean" );		//模擬使用者登出
		
		session.setAttribute( "MyBean", bean );	//等 timeout 
	}

}
